Lists
A list is a sequence of one or more list items of the same type. The list items may be separated by any number of blank lines.
Two list items are of the same type if they begin with a list marker of the same type. Two list markers are of the same type if (a) they are bullet list markers using the same character (-
, +
, or *
) or (b) they are ordered list numbers with the same delimiter (either .
or )
).
A list is an ordered list if its constituent list items begin with ordered list markers, and a bullet list if its constituent list items begin with bullet list markers.
The start number of an ordered list is determined by the list number of its initial list item. The numbers of subsequent list items are disregarded.
A list is loose if any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is tight. (The difference in HTML output is that paragraphs in a loose list are wrapped in <p>
tags, while paragraphs in a tight list are not.)
Changing the bullet or ordered list delimiter starts a new list:
Example 281
Markdown | HTML | Demo |
---|---|---|
|
|
Example 282
Markdown | HTML | Demo |
---|---|---|
|
|
In CommonMark, a list can interrupt a paragraph. That is, no blank line is needed to separate a paragraph from a following list:
Example 283
Markdown | HTML | Demo |
---|---|---|
|
|
Markdown.pl
does not allow this, through fear of triggering a list via a numeral in a hard-wrapped line:
The number of windows in my house is
14. The number of doors is 6.
Oddly, though, Markdown.pl
does allow a blockquote to interrupt a paragraph, even though the same considerations might apply.
In CommonMark, we do allow lists to interrupt paragraphs, for two reasons. First, it is natural and not uncommon for people to start lists without blank lines:
I need to buy
- new shoes
- a coat
- a plane ticket
Second, we are attracted to a
principle of uniformity: if a chunk of text has a certain meaning, it will continue to have the same meaning when put into a container block (such as a list item or blockquote).
(Indeed, the spec for list items and block quotes presupposes this principle.) This principle implies that if
* I need to buy
- new shoes
- a coat
- a plane ticket
is a list item containing a paragraph followed by a nested sublist, as all Markdown implementations agree it is (though the paragraph may be rendered without <p>
tags, since the list is “tight”), then
I need to buy
- new shoes
- a coat
- a plane ticket
by itself should be a paragraph followed by a nested sublist.
Since it is well established Markdown practice to allow lists to interrupt paragraphs inside list items, the principle of uniformity requires us to allow this outside list items as well. (reStructuredText takes a different approach, requiring blank lines before lists even inside other list items.)
In order to solve of unwanted lists in paragraphs with hard-wrapped numerals, we allow only lists starting with 1
to interrupt paragraphs. Thus,
Example 284
Markdown | HTML | Demo |
---|---|---|
|
|
We may still get an unintended result in cases like
Example 285
Markdown | HTML | Demo |
---|---|---|
|
|
but this rule should prevent most spurious list captures.
There can be any number of blank lines between items:
Example 286
Markdown | HTML | Demo |
---|---|---|
|
|
Example 287
Markdown | HTML | Demo |
---|---|---|
|
|
To separate consecutive lists of the same type, or to separate a list from an indented code block that would otherwise be parsed as a subparagraph of the final list item, you can insert a blank HTML comment:
Example 288
Markdown | HTML | Demo |
---|---|---|
|
|
Example 289
Markdown | HTML | Demo |
---|---|---|
|
|
List items need not be indented to the same level. The following list items will be treated as items at the same list level, since none is indented enough to belong to the previous list item:
Example 290
Markdown | HTML | Demo |
---|---|---|
|
|
Example 291
Markdown | HTML | Demo |
---|---|---|
|
|
Note, however, that list items may not be indented more than three spaces. Here - e
is treated as a paragraph continuation line, because it is indented more than three spaces:
Example 292
Markdown | HTML | Demo |
---|---|---|
|
|
And here, 3. c
is treated as in indented code block, because it is indented four spaces and preceded by a blank line.
Example 293
Markdown | HTML | Demo |
---|---|---|
|
|
This is a loose list, because there is a blank line between two of the list items:
Example 294
Markdown | HTML | Demo |
---|---|---|
|
|
So is this, with a empty second item:
Example 295
Markdown | HTML | Demo |
---|---|---|
|
|
These are loose lists, even though there is no space between the items, because one of the items directly contains two block-level elements with a blank line between them:
Example 296
Markdown | HTML | Demo |
---|---|---|
|
|
Example 297
Markdown | HTML | Demo |
---|---|---|
|
|
This is a tight list, because the blank lines are in a code block:
Example 298
Markdown | HTML | Demo |
---|---|---|
|
|
This is a tight list, because the blank line is between two paragraphs of a sublist. So the sublist is loose while the outer list is tight:
Example 299
Markdown | HTML | Demo |
---|---|---|
|
|
This is a tight list, because the blank line is inside the block quote:
Example 300
Markdown | HTML | Demo |
---|---|---|
|
|
This list is tight, because the consecutive block elements are not separated by blank lines:
Example 301
Markdown | HTML | Demo |
---|---|---|
|
|
A single-paragraph list is tight:
Example 302
Markdown | HTML | Demo |
---|---|---|
|
|
Example 303
Markdown | HTML | Demo |
---|---|---|
|
|
This list is loose, because of the blank line between the two block elements in the list item:
Example 304
Markdown | HTML | Demo |
---|---|---|
|
|
Here the outer list is loose, the inner list tight:
Example 305
Markdown | HTML | Demo |
---|---|---|
|
|
Example 306
Markdown | HTML | Demo |
---|---|---|
|
|